<!DOCTYPE html>
<html lang="en">
<head>
  <title>浩然金融中心管理平台</title>
  <meta charset="utf-8">
  <meta content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0"
        name="viewport">
  <#include "/common/jqgridlib.html">
</head>
<body>
<div class="listPage" id="listPage">
  <input id="appNo" name="appNo" type="hidden" value="${appNo }"/>
  <!-- 查询 -->
  <div class="filterField" id="filterField">
    项目名称：<input filterType="like" id="projectName" name="projectName" type="text"/>
  </div>
  <table class="table table-striped table-bordered table-hover text-center" id="tableDemo" style="width:100%"></table>
  <div id="pagerDemo"></div>
</div>
<script type="text/javascript">
    $(function () {
        CtrLoanContManager = {
            init: function () {
                //pageInit();
            },
            addClick: function () {
                alert('add');
            },
            editClick: function () {
                alert('edit');
            },
            delClick: function () {
                alert('delete');
            }
        };
        CtrLoanContManager.init();
    });
</script>
<!-- 封装jqGrid参数 -->
<script type="text/javascript">
    $(function () {
        var jqHeight = $(window).height - $("#divFilter").height() - $("#divOper").height() - 75;
        var jqGrid_tableDemo = $("#tableDemo").jqGrid({
            colModel: [
                {name: 'id', index: 'id', width: 155},
                {name: 'invdate', index: 'invdate', width: 190},
                {name: 'name', index: 'name asc, invdate', width: 150},
                {name: 'amount', index: 'amount', width: 180, align: "right"},
                {name: 'tax', index: 'tax', width: 180, align: "right"},
                {name: 'total', index: 'total', width: 180, align: "right"},
                {name: 'note', index: 'note', width: 250, sortable: false}
            ],
            url: '/demo/initData',
            datatype: "json",
            pager: '#pagerDemo',
            rowNum: 10,
            rowList: [2, 5, 10, 15, 20, 25, 30, 50, 100],
            caption: "用户信息表",
            rownumbers: true,
            gridview: true,//IE8会导致脚本报错
            recordpos: 'right',
            viewrecords: true, //显示记录
            sortorder: "desc",
            multiselect: true, //多选
            //multiboxonly: ${!multiselect},//单选一
            jsonReader: {
                id: "id",
                repeatitems: false
            },
            height: jqHeight,
            width: "100%",
            shrinkToFit: true,
            forceFit: true,
            hidegrid: false,
            altRows: true, //隔行底色
            toolbar: [true, "top"],
            cellLayout: 6,
            //loadComplete:${loadComplete},
            //beforeSelectRow:${beforeSelectRow},
            //onSelectAll:${onSelectAll},
            //onSelectRow:${onSelectRow},
            autowidth: true
        });
        $("#t_tableDemo").append('<table cellspacing="0" cellpadding="0" border="0" style="float:left;table-layout:auto;margin-top:2px" class="ui-pg-table topnavtable"><tr><td></td></tr></table>');
        //隐藏水平滚动条
        //	$("#tableDemo").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
        jqGrid_tableDemo.navGrid('#pagerDemo', {add: false, edit: false, del: false, search: false})
            .navButtonAdd('#pagerDemo', {
                caption: "新增",
                title: '添加新记录',
                buttonicon: "ui-icon-plus",
                onClickButton: function ($btn) {
                    CtrLoanContManager.addClick(jqGrid_tableDemo, $btn);
                },
                position: "last"
            })
            .navSeparatorAdd("#pagerDemo", {sepclass: "ui-separator", sepcontent: ''})
            .navButtonAdd('#pagerDemo', {
                caption: "编辑",
                title: '编辑选中记录',
                buttonicon: "ui-icon-pencil",
                onClickButton: function ($btn) {
                    var selectedIds = jqGrid_tableDemo.jqGrid("getGridParam", "selarrrow");
                    if (selectedIds == '') {
                        Jmts.tips("请选择需要编辑的记录!", 1);
                        return false;
                    }
                    if ((selectedIds + "").indexOf(",") != -1) {
                        Jmts.tips("每次只能编辑一条记录!", 1);
                        return false;
                    }
                    //return false;
                    var $rowData = jqGrid_tableDemo.jqGrid("getRowData", selectedIds);
                    CtrLoanContManager.editClick(jqGrid_tableDemo, $rowData);
                },
                position: "last"
            })
            .navSeparatorAdd("#pagerDemo", {sepclass: "ui-separator", sepcontent: ''})
            .navButtonAdd('#pagerDemo', {
                caption: "删除",
                title: "删除选中记录",
                buttonicon: "ui-icon-trash",
                onClickButton: function ($btn) {
                    var selectedIds = jqGrid_tableDemo.jqGrid("getGridParam", "selarrrow");
                    if (selectedIds == '') {
                        Jmts.tips("请选择需要删除的记录!", 1);
                        return false;
                    }
                    //return false;
                    CtrLoanContManager.delClick(jqGrid_tableDemo, selectedIds + "");
                },
                position: "last"
            });
        //使jqgrid自适应大小：
        (function () {
            var resizeTimer = null;
            resizeGrid();
            pageHanization();
            // 窗口大小改变的时候
            window.onresize = function () {
                if (resizeTimer == null) {
                    resizeTimer = setTimeout(function () {
                        resizeGrid();
                    }, 500);
                }
            };

            function resizeGrid() {
                var size = getWidthAndHeigh(true);
                jqGrid_tableDemo.jqGrid('setGridWidth', size.width);//.jqGrid('setGridHeight', size.height);
                resizeTimer = null;
            }

            // 获取父元素大小
            function getWidthAndHeigh(resize) {
                var width = $("#gbox_tableDemo").parent().width() - 10;
                var height = $("#gbox_tableDemo").parent().height() + 30;
                // chrome
                //	if ($.browser.chrome) {
                //		width -= 2;height -= 104;
                //	}
                // firefox
                //	else if ($.browser.mozilla) {
                //		width -= 2;height -= 108;
                //	}
                // IE
                //	else {
                width -= 1;//height -= 106;
                //	}
                return {width: width, height: height};
            }

            //pager按钮初始化
            function pageHanization() {
                $('#last_pagerDemo').html("尾页").css({"min-width": "40px"});
                $('#first_pagerDemo').html("首页").css({"min-width": "40px"});
                $('#prev_pagerDemo').html("上一页").css({"min-width": "40px"});
                $('#next_pagerDemo').html("下一页").css({"min-width": "40px"});
                $('#pagerDemo_left table').hide();
            }
        })();
    });
</script>
</body>
</html>
